# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/topics/item-pipeline.html
import codecs
from scrapy.xlib.pydispatch import dispatcher
from scrapy import signals

class SpiderPipeline(object):

    def __init__(self):
        dispatcher.connect(self.spider_opened, signals.spider_opened)
        dispatcher.connect(self.spider_closed, signals.spider_closed)
    
    def spider_opened(self):
        self.outfile = codecs.open("data.xls", "w", "GB18030")
    
    def spider_closed(self):
        self.outfile.close()
		
    def process_item(self, item, spider):
        #line = u"\t".join(item.values()) + u"\n"
        self.outfile.write(unicode(line))
        return item
